package com.im.netty;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

import javax.annotation.Resource;

/**
 * @Author: szw
 * @Date: 2021/5/10 17:30
 */
@ComponentScan(basePackages = {"com.im.*"})
@Configuration
@Slf4j
public class NettyBooter implements ApplicationListener<ContextRefreshedEvent> {
    @Resource
    NettyServer nettyServer;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if(contextRefreshedEvent.getApplicationContext().getParent() == null){
            try {
                //开启WebSocket服务
                nettyServer.start();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
